var setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "pId",
            rootPId: 0
        }
    },
    async: {
        enable: true
    },
    check: {
        enable: true, //true / false 分别表示 显示 / 不显示 复选框或单选框
        autoCheckTrigger: true, //true / false 分别表示 触发 / 不触发 事件回调函数
        chkStyle: "checkbox", //勾选框类型(checkbox 或 radio）
        chkboxType: {
            "Y": "s",
            "N": "s"
        } //勾选 checkbox 对于父子节点的关联关系
    },
    callback: {
        onCheck: zTreeOnCheck,
        // onDblClick: null,
        // onRightClick: null,
        // beforeMouseDown: null,
        // onDrop: null,
        // //beforeDrag: null,
        // beforeDrop: null
    }
};
var group_png = '../../static/img/layers/group.png';
var image_png = '../../static/img/layers/image.png';
var imageLayer_png = '../../static/img/layers/imageLayer.png';
var label_png = '../../static/img/layers/label.png';
var location_png = '../../static/img/layers/location.png';
var pointLayer_png = '../../static/img/layers/pointLayer.png';
var polygon_png = '../../static/img/layers/polygon.png';
var polygonLayer_png = '../../static/img/layers/polygonLayer.png';
var polyline_png = '../../static/img/layers/polyline.png';

var zNodes = parent.sgworld.ProjectTree.Source;
for (var i = 0; i < zNodes.length; i++) {
    zNodes[i].checked = false;
    getIcon(zNodes[i]);
}
var thisTree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);

function zTreeOnCheck() {
    if (thisTree) {
        var checkNodes = thisTree.getCheckedNodes(true);
        parent.BrowsingMode.selectNodes = checkNodes;
    }
}

function getIcon(item) {
    switch (item.type) {
        case "label":
            item.icon = label_png;
            break;
        case "Imagelabel":
            item.icon = image_png;
            break;
        case "group":
            item.icon = group_png;
            break;
        case "polyline":
            item.icon = polyline_png;
            break;
        case "polygon":
            item.icon = polygon_png;
            break;
        case "polygonLayer":
            item.icon = polygonLayer_png;
            break;
        case "Location":
        case "Point":
            item.icon = location_png;
            break;
        case "imageLayer":
            item.icon = imageLayer_png;
            break;
        case "pointLayer":
            item.icon = pointLayer_png;
            break;
        default:
            break;
    }
}